/**
 * @description  交易所基础信息（债券指令）
 *
 */
import { Form } from '@ant-design/compatible';

import '@ant-design/compatible/assets/index.css';
import { connect } from 'dva';
import moment from 'moment';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';

import { DATA_ENTRY, FormGroup, codeType } from '../../../../../comps';
import { isZiGuanEvir, calculateFee } from '../../../../../utils/commonFunc';
import investmentType from '../../../../../utils/enumeratedValues/investmentType';
import style from '../../TradForm1/index.less';

@Form.create()
class DaZongBondFormC extends PureComponent {
  // eslint-disable-next-line react/static-property-placement
  static defaultProps = {
    onRef: () => {},
  };

  constructor() {
    super();
    this.state = {
      showRate: true,
      SecuritiesCode: undefined, // 计算买入收益率和买入行权收益率用的证券代码相关数据
      price: undefined, // 净价
      date: moment().format('YYYYMMDD'), // 结算日期
      accruedInterest: undefined, // 应计利息
      orderQty: undefined, // 数量
      fullPrice: undefined, // 全价
      externalNameInfo: undefined, // 交易对手
      bussniessVisible: false, // 业务目标编辑补充是否可见
      addSPPIFlag: false, // 点击了新增测试按钮
      SPPI_result: undefined, // 根据证券代码获取sppi结果
      objectives: undefined, // 选中的业务目标
      objectivesEditObj: {}, // 缓存每一个业务目标对应的编辑
      editContent: {}, // 业务目标编辑内容
      investmentTypeList: [...investmentType], // 投资类型下拉
      tradeDirect: '1', // 交易方向
      isZiGuan: false,
      feeData: {
        // 费用自动计算条件
        productId: undefined,
        portfolioid: undefined,
        tradingCode: undefined,
        exchangecode: undefined,
        trademarket: 'dzpt',
        sectype: 'bond',
        orderside: '1',
        price: undefined,
      },
    };
  }

  componentDidMount() {
    const { info } = this.props;
    this.props.onRef(this);
    if (info) {
      // 二次确时收益率会变成整数
      this.formGroupThis.props.form.setFieldsValue({
        yield: info.trade25.yield, // 清空买入收益率
        exerciseYield: info.trade25.exerciseYield, // 清空行权买入收益率
      });
      this.setState({
        // 详情时取业务目标的值
        objectives: this.props.info && this.props.info.trade25 ? this.props.info.trade25.bussinessObjectives : undefined,
        editContent: this.props.info.trade25 ? this.props.info.trade25 : {},
      });
    }
    const temp = isZiGuanEvir();
    const isZiGuan = !!temp; // 判断该页面是在资管被引入的，还是maat
    this.setState({ isZiGuan });
  }

  // 清空表单
  // eslint-disable-next-line react/no-unused-class-component-methods
  reset = () => {
    const { form } = this.formGroupThis.props;
    this.props.portfolioOnChange(undefined);
    this.props.tradingcodeOnChange(undefined); // 重置组合id和证券代码
    form.resetFields();
    this.setState({
      showRate: true,
      SecuritiesCode: undefined, // 计算买入收益率和买入行权收益率用的证券代码相关数据
      price: undefined, // 净价
      accruedInterest: undefined, // 应计利息
      orderQty: undefined, // 数量
      fullPrice: undefined, // 全价
      date: moment().format('YYYYMMDD'), // 结算日期
      bussniessVisible: false, // 业务目标编辑补充是否可见
      addSPPIFlag: false, // 点击了新增测试按钮
      SPPI_result: undefined, // 根据证券代码获取sppi结果
      objectives: undefined, // 选中的业务目标
      objectivesEditObj: {}, // 缓存每一个业务目标对应的编辑
      editContent: {}, // 业务目标编辑内容
      investmentTypeList: [...investmentType], // 投资类型下拉
      tradeDirect: '1', // 交易方向
    });
  };

  // 费用自动计算
  changeFee = (type, data) => {
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    if (this.props.type == 3 || this.props.type == 4) return; // 详情不计算
    setTimeout(() => {
      if (data == undefined) {
        setFieldsValue({ fee: undefined });
        if (type == 'tradingCode') {
          this.setState({ feeData: { ...this.state.feeData, tradingCode: undefined, exchangecode: undefined } });
        } else if (type == 'productId') {
          this.setState({ feeData: { ...this.state.feeData, productId: undefined, portfolioid: undefined } });
        } else {
          this.setState({ feeData: { ...this.state.feeData, [type]: undefined } });
        }
      } else if (type == 'tradingCode') {
        this.setState({ feeData: { ...this.state.feeData, tradingCode: data.tradingCode, exchangecode: data.exchangeCode } }, () => {
          const fee = calculateFee(this.state.feeData);
          fee.then((r) => {
            setFieldsValue({ fee: r });
          });
        });
      } else {
        this.setState({ feeData: { ...this.state.feeData, [type]: data } }, () => {
          const fee = calculateFee(this.state.feeData);
          fee.then((r) => {
            setFieldsValue({ fee: r });
          });
        });
      }
    }, 100);
  };

  // 交易方向改变执行方法
  changeDirect = (e) => {
    const { type } = this.props;
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    this.setState(
      {
        tradeDirect: e.value,
      },
      () => {
        if (this.props.type < 3) {
          // 交易方向改变 对投资类型的影响 1买入 2卖出
          this.setSelectList();
        }
      },
    );
    if (type != '3' && type != '4') {
      if (e) {
        if (e.value == '1') {
          const flag = this.state.showRate;
          this.setState(
            {
              showRate: true,
            },
            () => {
              if (!flag || this.props.info) {
                this.getRate();
              }
            },
          );
          setFieldsValue({
            accruedInterest: this.state.accruedInterest,
          });
        } else {
          this.setState({ showRate: false });
          if (e.value == '4') {
            // 交易方向为“债回售”时，全价、净价、应计利息、金额设为disabled状态，清空，无需必填校验；
            if (this.props.info) {
              // 详情时展示金额
              setFieldsValue({
                fullPrice: undefined,
                accruedInterest: undefined,
                price: undefined,
              });
            } else {
              setFieldsValue({
                fullPrice: undefined,
                amount: undefined,
                accruedInterest: undefined,
                price: undefined,
              });
              this.changeFee('price', undefined);
              this.setState(
                {
                  price: undefined,
                  fullPrice: undefined,
                },
                () => {
                  this.getSPPI_Result(); // 清空sppi结果 和 校验投资类型值
                },
              );
            }
          } else {
            setFieldsValue({
              accruedInterest: this.state.accruedInterest,
            });
          }
        }
      }
    }
  };

  // 证券代码改变事件
  changePort = (e) => {
    const { price } = this.state;
    const {
      dispatch,
      info,
      bondDeviationDetailM: { isConvertibleBond = false },
    } = this.props;
    const {
      form: { setFieldsValue, getFieldsValue, resetFields },
    } = this.formGroupThis.props;
    this.setState({
      // 交易市场 给约定号判断用
      market: e ? `${e.exchangeCode == '101' ? 1 : 2}` : undefined,
    });
    resetFields(['engagedId']); // 清空约定号数据 重新校验
    if (e) {
      this.setState(
        {
          SecuritiesCode: e,
        },
        () => {
          this.getRate(); // 获取行权收益率
          this.getSPPI_Result();
        },
      );

      if (getFieldsValue().orderSide != '4') {
        dispatch({
          type: 'bondTradeM/getInterest',
          payload: {
            secucode: e.secucode, // 根据证券代码获取应计利息
          },
          callback: (res) => {
            this.setState({
              accruedInterest: res.data.accruedInterest,
            });
            setFieldsValue({
              accruedInterest: res.data.accruedInterest, // 赋值应计利息
            });
            if (price !== undefined) {
              const nums = parseFloat((res.data.accruedInterest + price).toFixed(isConvertibleBond && e?.exchangeCode == '101' ? 2 : 3)); // 全价=净价+应计利息
              setFieldsValue({
                fullPrice: nums,
              });
              this.amountCalc(nums);
            }
          },
        });
      }
    } else {
      setFieldsValue({
        yield: undefined, // 清空买入收益率
        exerciseYield: undefined, // 清空行权买入收益率
        accruedInterest: undefined, // 清空应计利息
        securityExchange: '', // 清空交易市场
      });
      this.setState(
        {
          SecuritiesCode: undefined,
        },
        () => {
          this.getSPPI_Result();
        },
      );
    }
    if (info) return; // 详情时不进入判断
    setFieldsValue({
      securityExchange: e ? `${e.exchangeCode == '101' ? 1 : 2}` : undefined,
    });
  };

  // 获取sppi结果
  getSPPI_Result = () => {
    const { SecuritiesCode, price } = this.state;
    if (this.props.type < 3) {
      if (SecuritiesCode && price != undefined) {
        // 证券代码和价格都不为空
        this.props.dispatch({
          type: 'bondTradeM/getSPPIResult',
          payload: {
            exchangeCode: SecuritiesCode.exchangeCode,
            tradingCode: SecuritiesCode.tradingCode,
            price,
          },
          callback: (data) => {
            let temp;
            if (data) {
              // sppi有值 不可点击新增按钮  无值可以
              temp = data.rgpd;
            } else {
              temp = undefined;
            }
            this.setState(
              {
                SPPI_result: temp,
              },
              () => {
                this.formGroupThis.props.form.setFieldsValue({
                  SPPI_result: this.state.SPPI_result,
                });
                this.setSelectList();
              },
            );
          },
        });
      } else {
        this.setState(
          {
            SPPI_result: undefined,
          },
          () => {
            this.formGroupThis.props.form.setFieldsValue({
              SPPI_result: this.state.SPPI_result,
            });
            this.setSelectList();
          },
        );
      }
    }
  };

  // 设置投资类型下拉 并确定默认值
  setSelectList = () => {
    /**
     *     // 以收取该金融资产合同现金流量为目的  是  AC
     *     // 以收取该金融资产合同现金流量为目的  否  FVTPL
     *     // 以收取该合同现金流量及出售金融资产为目的  是  FVOCI
     *     // 以收取该合同现金流量及出售金融资产为目的  否  FVTPL
     *     // 其他  是 or 否  FVTPL
     */
    // eslint-disable-next-line camelcase
    const { SPPI_result, objectives, tradeDirect } = this.state;
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    if (tradeDirect == '1') {
      // 交易方向为买入
      // eslint-disable-next-line camelcase
      if (SPPI_result == undefined || objectives == undefined) {
        setFieldsValue({
          investmentType: undefined,
        });
        this.setState({
          investmentTypeList: investmentType,
        });
        return;
      }
      let arr = [];
      // eslint-disable-next-line camelcase
      if (objectives == 1 && SPPI_result == 1) {
        // AC
        arr = [{ value: 'AC', title: 'AC' }];
        setFieldsValue({
          investmentType: 'AC',
        });
        // eslint-disable-next-line camelcase
      } else if ((objectives == 1 && SPPI_result == 2) || (objectives == 2 && SPPI_result == 2) || (objectives == 4 && SPPI_result)) {
        // FVTPL
        arr = [{ value: 'FVTPL', title: 'FVTPL' }];
        setFieldsValue({
          investmentType: 'FVTPL',
        });
        // eslint-disable-next-line camelcase
      } else if (objectives == 2 && SPPI_result == 1) {
        // FVOCI
        arr = [{ value: 'FVOCI', title: 'FVOCI' }];
        setFieldsValue({
          investmentType: 'FVOCI',
        });
      } else {
        arr = [...investmentType];
        setFieldsValue({
          investmentType: undefined,
        });
      }
      this.setState({
        investmentTypeList: [...arr],
      });
    } else if (tradeDirect == '2') {
      // 交易方向卖出 请求新的接口
      this.setState({
        investmentTypeList: [...investmentType],
      });
      setFieldsValue({
        investmentType: this.props.investmentType,
      });
    }
  };

  // 业绩目标修改
  changeObjectives = (e) => {
    this.setState(
      {
        objectives: e,
      },
      () => {
        this.setSelectList();
      },
    );
  };

  // 获取行权收益率
  getRate = () => {
    const { SecuritiesCode, date, price, showRate } = this.state;
    const { dispatch, businessType, info } = this.props;
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    if (businessType && SecuritiesCode && price && date && showRate) {
      const query = {
        // 区分新增和回填时请求行权收益率的入参取值不同
        tradingcode: SecuritiesCode.tradingCode,
        exchangeCode: SecuritiesCode.exchangeCode,
        date,
        price,
        type: businessType,
      };
      dispatch({
        type: 'bondTradeM/getRate',
        payload: {
          ...query,
        },
        callback: (res) => {
          const { data } = res;
          setFieldsValue({
            yield: data.yield !== null ? data.yield : undefined,
            exerciseYield: data.exerciseYield !== null ? data.exerciseYield : undefined,
          });
        },
      });
    } else {
      if (info) return;
      setFieldsValue({
        yield: undefined,
        exerciseYield: undefined,
      });
    }
  };

  // 净价改变事件
  changeprice = (e) => {
    const {
      form: { setFieldsValue, getFieldsValue },
    } = this.formGroupThis.props;
    const { accruedInterest, market } = this.state;
    const {
      bondDeviationDetailM: { isConvertibleBond = false },
    } = this.props;
    this.setState(
      {
        price: typeof e == 'number' ? e : undefined, // 把价格放入state方便数量改变时取值使用
      },
      () => {
        if (typeof e == 'string') return; // 当值为123B  这样的数据不请求
        this.getSPPI_Result(); // 清空sppi结果 和 校验投资类型值
        if (typeof e == 'number') {
          this.getRate(); // 获取行权收益率
          if (getFieldsValue().orderSide == '4') return; // 债回售 不做计算
          if (accruedInterest !== undefined) {
            const num = parseFloat((e + accruedInterest).toFixed(isConvertibleBond && market == 1 ? 2 : 3)); // 全价
            setFieldsValue({
              fullPrice: num, // 赋值全价
            });
            this.amountCalc(num); /// 全价变更 则金额需要变更
          }
        }
      },
    );
  };

  amountCalc = (num) => {
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    this.setState({
      fullPrice: num,
    });
    // 全价变更 则金额需要变更
    if (this.state.orderQty !== undefined) {
      const nums = num * this.state.orderQty; // 赋值金额
      setFieldsValue({
        amount: nums, // 金额
      });
      this.changeFee('price', nums);
    } else {
      setFieldsValue({
        amount: '', // 清空金额
      });
      this.changeFee('price', undefined);
    }
  };

  // 全价改变事件
  changefullPrice = (e) => {
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    const { accruedInterest, orderQty } = this.state;
    this.setState({
      fullPrice: typeof e === 'number' ? e : undefined,
    });
    if (typeof e === 'number' && accruedInterest !== undefined) {
      const num = e - accruedInterest; // 赋值净价
      setFieldsValue({
        price: num,
      });
      this.setState(
        {
          price: num,
        },
        () => {
          // 价格变动对sppi结果的影响
          this.getSPPI_Result();
        },
      );
    }
    // 全价变更 金额变更
    if (typeof e === 'number' && orderQty !== undefined) {
      this.amountCalc(e);
    }
  };

  // 数量改变事件
  changeorderQty = (e) => {
    const {
      form: { setFieldsValue, getFieldValue },
    } = this.formGroupThis.props;
    this.setState({
      orderQty: typeof e === 'number' ? e : undefined,
    });
    if (typeof e === 'number' && typeof getFieldValue('fullPrice') == 'number') {
      const num = e * getFieldValue('fullPrice'); // 金额
      setFieldsValue({
        amount: num,
      });
      this.changeFee('price', num);
    } else {
      setFieldsValue({
        amount: undefined,
      });
      this.changeFee('price', undefined);
    }
  };

  // 结算日期改变事件
  changeDate = (e) => {
    if (e) {
      this.setState(
        {
          date: e.format('YYYYMMDD'),
        },
        () => {
          this.getRate();
        },
      );
    } else {
      this.formGroupThis.props.form.setFieldsValue({
        yield: undefined,
        exerciseYield: undefined,
      });
    }
  };

  selectSpeed = (value) => {
    const {
      form: { setFieldsValue },
    } = this.formGroupThis.props;
    const { dispatch } = this.props;

    if (value === '1') {
      setFieldsValue({
        settlementDate: moment(),
      });
    } else {
      dispatch({
        type: 'bondTradeM/queryNextTranDt',
        payload: {
          date: moment().format('YYYYMMDD'),
          days: value - 1,
        },
        callback: (data) => {
          if (data) {
            setFieldsValue({
              settlementDate: moment(data),
            });
          }
        },
      });
    }
  };

  // 表单内容
  formContent = () => {
    const {
      // eslint-disable-next-line camelcase
      showRate,
      SPPI_result,
      SecuritiesCode,
      investmentTypeList,
      isZiGuan,
      tradeDirect,
      market,
    } = this.state;
    const {
      info,
      type,
      businessType,
      isSecondShow,
      globalM: {
        dataDictionary: { SPPI_USER_DEFINEDTYPE = [] },
      },
      bondDeviationDetailM: { isConvertibleBond = false },
    } = this.props;
    const securityIdVal = info && info.trade25 && info.trade25.securityId ? `${info.trade25.securityId.split('-')[1]}-${info.trade25.securityId.split('-')[2]}` : undefined;
    const qssd = [
      { title: 'T+0', value: '1' },
      { title: 'T+1', value: '2' },
    ];
    const tenant = localStorage.getItem('antd-pro-tenant');
    return (
      <FormGroup
        dataSource={[
          {
            dataIndex: ['productId', 'portfolioId'],
            positionBody: true,
            type: DATA_ENTRY.PRODUCTGROUPSEP,
            multipleGroup: false,
            initialValue: type == '3' || type == '4' ? (isSecondShow ? [info.productId, info.portfolioId] : [info.portfolioInfoId, info.productId]) : undefined,
            disabled: !!(type == '3' || type == '4'),
            rules: [[{ required: true, message: '请选择产品!' }], [{ required: true, message: '请选择组合!' }]],
            groupOnChange: (e) => {
              this.props.portfolioOnChange(e ? e.key : undefined); // 向外抛处组合id
              this.props.portfolioCode(e ? e.info.portfolioCode : undefined); // 向外抛出组合code
              this.changeFee('portfolioid', e ? e.key : undefined);
            },
            productOnChange: (e) => {
              this.changeFee('productId', e ? e.key : undefined);
              this.props.productCode(e ? e.info.portfolioCode : undefined); // 向外抛出产品code
            },
            authority: 'write', // 可写权限
            exist: 1,
            span: 24,
            tradeModel: type == 1 || type == 2 ? ['BOOKKEEPING_MODE', 'COMMAND_MODE'] : undefined, // 不包含估值解析和估值对接的产品
          },
          {
            title: '证券代码',
            positionBody: true,
            type: DATA_ENTRY.SECURITIESCODE,
            initialValue: type == '3' || type == '4' ? securityIdVal : undefined,
            dataIndex: 'securityId',
            codeType: codeType.zq,
            // queryItems: { exchangeCode: '101,105', categorycode: 'a101020600' },  // 101-深交所，105-上交所,可转债
            queryItems: { exchangeCode: '101,105', type: 'dzxq' }, // 0708查到深市可转债和沪市定向可转债
            onChange: (e) => {
              if (this.props.info) return;
              this.changePort(e);
              this.props.tradingcodeOnChange(e);
              this.changeFee('tradingCode', e || undefined);
            },
            disabled: !!(type == '3' || type == '4'),
            rules: [{ required: true, message: '请选择证券代码!' }],
            span: 12,
          },
          {
            title: '交易市场',
            type: DATA_ENTRY.TRADINGMARKET,
            dataIndex: 'securityExchange',
            dataType: 2,
            initialValue: type == '3' || type == '4' ? info.trade25.securityExchange : undefined,
            marketType: ['jys'],
            rules: [{ required: true, message: '请选择交易市场!' }],
            disabled: true,
            span: 12,
            onRef: (ref) => (this.formGroupThis = ref),
          },
          {
            dataIndex: 'orderSide',
            type: DATA_ENTRY.TRADINGDIRECT,
            initialValue: type == '3' || type == '4' ? info.trade25.orderSide : '1',
            rules: [{ required: true, message: '请选择交易方向!' }],
            multiple: false,
            disabled: !!(type == 3 || type == '4'),
            businessType,
            placeholder: '请选择',
            onChange: (e) => {
              this.changeDirect(e);
              this.changeFee('orderside', e ? e.value : undefined);
            },
            allowClear: false,
            span: 12,
          },
          {
            title: '约定号',
            type: DATA_ENTRY.INPUT,
            dataIndex: 'engagedId',
            placeholder: '请输入',
            initialValue: type == '3' || type == '4' ? info.trade25.engagedId : undefined,
            disabled: type == '3' || type == '4' ? true : !this.state.market,
            rules: [
              { required: true, message: '请输入约定号!' },
              { pattern: this.state.market == 1 ? /^.{6}$/ : /^.{1,8}$/, message: this.state.market == 1 ? '约定号必须等于6位数' : '约定号小于或等于8位数' },
            ],
            span: 12,
          },
          {
            title: '清算速度',
            type: DATA_ENTRY.SELECT,
            dataIndex: 'settlementSpeed',
            dataSource: qssd,
            initialValue: type == '3' || type == '4' ? info.trade25.settlementSpeed : '1',
            disabled: !!(type == '3' || type == '4'),
            rules: [{ required: true, message: '请选择清算速度!' }],
            multiple: false,
            placeholder: '请选择',
            onChange: this.selectSpeed,
            span: 12,
          },
          {
            title: '结算日期',
            dataIndex: 'settlementDate',
            type: DATA_ENTRY.SINGLEDATE,
            initialValue: type == '3' || type == '4' ? moment(info.trade25.settlementDate) : moment(),
            disabled: !!(type == '3' || type == '4'),
            onChange: (e) => this.changeDate(e),
            disableBegin: moment().subtract(1, 'days'),
            rules: [{ required: true, message: '请选择结算日期!' }],
            span: 12,
          },
          {
            title: '净价',
            dataIndex: 'price',
            type: DATA_ENTRY.INPUTNUMBER,
            placeholder: '请输入',
            precision: type == '3' || type == '4' ? (info.trade25.securityExchange == '1' ? 2 : 3) : isConvertibleBond && market == 1 ? 2 : 3,
            min: 0,
            splitStyle: true,
            max: 999999999999,
            initialValue: type == '3' || type == '4' ? info.trade25.price : undefined,
            disabled: type == '3' || type == '4' ? true : tradeDirect == '4',
            onChange: this.changeprice,
            rules: [{ required: tradeDirect != '4', message: `请输入净价` }],
            unit: '元',
            span: 12,
          },
          {
            title: '全价',
            dataIndex: 'fullPrice',
            type: DATA_ENTRY.INPUTNUMBER,
            placeholder: '请输入',
            precision: type == '3' || type == '4' ? (info.trade25.securityExchange == '1' ? 2 : 3) : isConvertibleBond && market == 1 ? 2 : 3,
            splitStyle: true,
            min: 0,
            max: 999999999999,
            initialValue: type == '3' || type == '4' ? info.trade25.fullPrice : undefined,
            disabled: type == '3' || type == '4' ? true : tradeDirect == '4',
            onChange: this.changefullPrice,
            rules: [{ required: tradeDirect != '4', message: `请输入全价` }],
            unit: '元',
            span: 12,
          },
          {
            title: '应计利息',
            dataIndex: 'accruedInterest',
            type: DATA_ENTRY.INPUTNUMBER,
            placeholder: '请输入',
            min: 0,
            precision: 4,
            initialValue: type == '3' || type == '4' ? info.trade25.accruedInterest : undefined,
            disabled: true,
            rules: [{ required: tradeDirect != '4', message: `请输入应计利息` }],
            unit: '元',
            span: 12,
          },
          {
            title: '数量',
            dataIndex: 'orderQty',
            placeholder: '请输入',
            type: DATA_ENTRY.INPUTNUMBER,
            min: 10,
            precision: 0,
            splitStyle: true,
            initialValue: type == '3' || type == '4' ? info.trade25.orderQty : undefined,
            rules: [
              { required: true, message: '请输入数量!' },
              { pattern: /^[+-]?(\d){1,}0$/, message: '请输入10的倍数' },
            ],
            disabled: !!(type == '3' || type == '4'),
            onChange: this.changeorderQty,
            unit: '张',
            span: 12,
          },
          {
            title: '金额',
            dataIndex: 'amount',
            placeholder: '请输入',
            type: DATA_ENTRY.INPUTNUMBER,
            min: 0,
            precision: 2,
            initialValue: type == '3' || type == '4' ? info.trade25.amount : undefined,
            disabled: true,
            splitStyle: true,
            rules: [{ required: tradeDirect != '4', message: `请输入金额` }],
            unit: '元',
            span: 12,
          },
          {
            dataIndex: 'externalName',
            type: DATA_ENTRY.TRADINGCOMPANY,
            initialValue: type == '3' || type == '4' ? info.trade25.externalName : undefined,
            multiple: false,
            disabled: !!(type == '3' || type == '4'),
            onChange: (e) => {
              this.setState({ externalNameInfo: e });
            },
            placeholder: '请选择',
            rules: [{ required: true, message: `请输入交易对手` }],
            span: 12,
            scenesType: type, // 组件场景类型，用于详情时根据ID回填值
          },
          {
            title: '对手席位号',
            type: DATA_ENTRY.INPUT,
            dataIndex: 'opponentTrading',
            placeholder: '请输入',
            initialValue: type == '3' || type == '4' ? info.trade25.opponentTrading : undefined,
            disabled: !!(type == '3' || type == '4'),
            rules: [{ required: true, message: '请输入对手席位号!' }],
            span: 12,
          },
          ...(showRate
            ? [
                {
                  title: '买入收益率',
                  dataIndex: 'yield',
                  type: DATA_ENTRY.INPUTNUMBER,
                  disabled: true,
                  precision: 2,
                  unit: '%',
                  span: 12,
                },
                {
                  title: '买入行权收益率',
                  dataIndex: 'exerciseYield',
                  type: DATA_ENTRY.INPUTNUMBER,
                  disabled: true,
                  precision: 2,
                  unit: '%',
                  span: 12,
                },
              ]
            : []),
          // {
          //   title: '费用',
          //   dataIndex: 'fee',
          //   placeholder: "请输入",
          //   type: DATA_ENTRY.INPUTNUMBER,
          //   min: 0,
          //   precision: 2,
          //   initialValue: type == '3' || type == '4' ? info.trade25.fee : '',
          //   splitStyle: true,
          //   disabled: type == '3' || type == '4' || tradeDirect == '4' ? true : false,
          //   unit: '元',
          //   span: 12
          // },
          ...(type < 5 && !isZiGuan
            ? [
                {
                  // 业务目标
                  dataIndex: 'bussinessObjectives',
                  type: DATA_ENTRY.BUSINESSTARGETC,
                  disabled: !!(type == '3' || type == '4'),
                  initialValue: type == '3' || type == '4' ? info?.trade25?.bussinessObjectives : undefined,
                  onChangeFn: this.changeObjectives,
                  TaretType: type,
                  info: this.state.editContent,
                  getLayerValue: this.getObjectEdit,
                  span: 24,
                },
                {
                  dataIndex: 'SPPI_result',
                  type: DATA_ENTRY.SPPIRESULTC,
                  title: 'SPPI结果',
                  initialValue: type == '3' || type == '4' ? info.trade25.sppiResult : undefined,
                  selectProps: {
                    SecuritiesCode,
                    rightContentShow: type < 3, // 右侧按钮是否展示，后面展示后的禁用逻辑，展示逻辑，组件控制
                    // eslint-disable-next-line camelcase
                    SPPI_result, // 根据证券代码切换获取SPPI结果
                    SppItype: 3,
                    sppITitle: '新增测试',
                  },
                  onOk: this.getSPPI_Result, // 新增完了 重新获取结果
                  span: 12,
                },
                {
                  dataIndex: 'investmentType',
                  type: DATA_ENTRY.SELECT,
                  title: '投资类型',
                  disabled: type == '3' || type == '4' ? true : this.state.tradeDirect == 2,
                  initialValue: type == '3' || type == '4' ? info.trade25.investmentType : undefined,
                  dataSource: investmentTypeList,
                  span: 12,
                },
              ]
            : []),
          ...(type < 5 && tenant == 'XAYH' && !isZiGuan
            ? [
                {
                  dataIndex: 'userDefinedType',
                  type: DATA_ENTRY.SELECT,
                  title: '自定义分类',
                  disabled: !!(type == '3' || type == '4'),
                  initialValue: type == '3' || type == '4' ? info.trade25.userDefinedType : undefined,
                  dataSource: SPPI_USER_DEFINEDTYPE.map((item) => ({ value: item.code, title: item.value })),
                  span: 12,
                },
              ]
            : []),
          {
            dataIndex: 'remark',
            type: DATA_ENTRY.INPUT,
            title: '备注',
            disabled: !!(type == '3' || type == '4'),
            initialValue: type == '3' || type == '4' ? info.remark : '',
            placeholder: '请输入',
            showTextArea: true,
            autosize: { minRows: 2, maxRows: 2 },
            span: 24,
          },
        ]}
        autoLayout={false}
      />
    );
  };

  // 获取校验并获取表单的值
  // eslint-disable-next-line react/no-unused-class-component-methods
  getInfo = () => {
    const {
      form: { validateFields },
    } = this.formGroupThis.props;
    let query;
    const { objectives, objectivesEditObj } = this.state;
    const obj = objectivesEditObj[objectives];
    validateFields((err, fieldsValue) => {
      if (!err) {
        query = fieldsValue;
        query.SecuritiesCode = this.state.SecuritiesCode;
        query.externalName = this.state.externalNameInfo;
        query.sppiResult = query.SPPI_result; // 修改入参名
        query.fee = 0; // 费用计算逻辑未完全梳理清楚，后续用户有真正需求时再添加费用计算相关逻辑
        delete query.SPPI_result;
        if (obj) {
          query.editObj = { ...obj };
        }
      }
    });
    return query;
  };

  // 存储每一个业绩目标对应的补充编辑
  getObjectEdit = (objectivesEditObj) => {
    this.setState({
      objectivesEditObj,
    });
  };

  render() {
    return <div className={style.info}>{this.formContent()}</div>;
  }
}
// props类型
DaZongBondFormC.propsTypes = {
  type: PropTypes.string, // 类型  (1-指令新增   2-簿记新增    3-详情 )
  info: PropTypes.object, // 设置表单布局
};
export default connect(({ bondTradeM, globalM, bondDeviationDetailM }) => ({
  bondTradeM,
  globalM,
  bondDeviationDetailM,
}))(DaZongBondFormC);
